%%-*- mode: erlang -*-
%% emq_auth_http config mapping
{mapping, "auth.http.auth_req", "emq_auth_http.auth_req", [
  {datatype, string}
]}.

{mapping, "auth.http.auth_req.method", "emq_auth_http.auth_req", [
  {default, post},
  {datatype, {enum, [post, get]}}
]}.

{mapping, "auth.http.auth_req.params", "emq_auth_http.auth_req", [
  {datatype, string}
]}.

{translation, "emq_auth_http.auth_req", fun(Conf) ->
  Params = cuttlefish:conf_get("auth.http.auth_req.params", Conf),
  [{url, cuttlefish:conf_get("auth.http.auth_req", Conf)},
   {method, cuttlefish:conf_get("auth.http.auth_req.method", Conf)},
   {params, [list_to_tuple(string:tokens(S, "=")) || S <- string:tokens(Params, ",")]}]
end}.

{mapping, "auth.http.super_req", "emq_auth_http.super_req", [
  {datatype, string}
]}.

{mapping, "auth.http.super_req.method", "emq_auth_http.super_req", [
  {default, post},
  {datatype, {enum, [post, get]}}
]}.

{mapping, "auth.http.super_req.params", "emq_auth_http.super_req", [
  {datatype, string}
]}.

{translation, "emq_auth_http.super_req", fun(Conf) ->
  case cuttlefish:conf_get("auth.http.super_req", Conf, undefined) of
    undefined -> cuttlefish:unset();
    Url -> Params = cuttlefish:conf_get("auth.http.super_req.params", Conf),
           [{url, Url}, {method, cuttlefish:conf_get("auth.http.super_req.method", Conf)},
            {params, [list_to_tuple(string:tokens(S, "=")) || S <- string:tokens(Params, ",")]}]
  end
end}.

{mapping, "auth.http.acl_req", "emq_auth_http.acl_req", [
  {default, undefined},
  {datatype, string}
]}.

{mapping, "auth.http.acl_req.method", "emq_auth_http.acl_req", [
  {default, post},
  {datatype, {enum, [post, get]}}
]}.

{mapping, "auth.http.acl_req.params", "emq_auth_http.acl_req", [
  {datatype, string}
]}.

{translation, "emq_auth_http.acl_req", fun(Conf) ->
  case cuttlefish:conf_get("auth.http.acl_req", Conf, undefined) of
    undefined -> cuttlefish:unset();
    Url -> Params = cuttlefish:conf_get("auth.http.acl_req.params", Conf),
           [{url, Url}, {method, cuttlefish:conf_get("auth.http.acl_req.method", Conf)},
            {params, [list_to_tuple(string:tokens(S, "=")) || S <- string:tokens(Params, ",")]}]
  end
end}.

{mapping, "auth.http.acl_nomatch", "emq_auth_http.acl_nomatch", [
  {default, deny},
  {datatype, {enum, [deny, allow]}}
]}.

